//定义图片的行数
var imgRow = 1;
//定义一行图片有几个
var imgCol = 4;
//定义请求的状态
var flags = true;
//给图片绑定点击事件
$('.item-box .item').each(function(imgIndex){
    if(imgIndex > 3) return;
    this.onclick = () =>{
        location.href = `./sellinfo.html#${imgIndex}`
    }
})
$(window).scroll(function () {
    let topNum = document.documentElement.scrollTop;
    if ((topNum / 429) > imgRow) {
        if (!flags) return;
        //创建盒子放置图片
        let area = $('<div class="item-box"></div>');
        var loadindex = layer.load(0, {
            shade: [0.6, "#000"]
        });
        $.get({
            url: './php/list.php',
            data: {
                id: 1
            },
            success: res => {
                var { meta: { status, msg, data } } = JSON.parse(res);
                layer.close(loadindex);
                if (status === 1) {
                    imgRow++;
                    flags = true;
                    for (let i = 0; i < imgCol; i++) {
                        let src = data[i].src;
                        //创建图片标签
                        let img = $(`<img class="item" src='${src}'>`);
                        area.append(img);
                    }
                    console.log(area);
                    $('.item-box:last').after(area)
                } else {
                    layer.msg(msg, {
                        icon: 2,
                        time: 1500
                    })
                }
            }
        })
        flags = false;
    }
})